home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TEXTFILE.SWG / 0011_VIEWER.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  92 lines

  1. {
  2. │I would like to be able to read a standard ASCII Text File from disk into
  3. │a section of memory so I would be able to call up the screen later.  How
  4. │would I accomplish this?  I'm assuming that once I have it in memory I could
  5. │copy the information into $B800 and so have it display on the screen.  This
  6. │would actually be useful For an instruction screen so I could scroll one
  7. │screenful at a time With PgDn.
  8.  
  9. Sample code For viewing Text File. Feel free to experiment With it. If you
  10. have any questions, just ask.
  11. }
  12.  
  13. Uses
  14.   Crt, Dos;
  15.  
  16.  
  17. Procedure ViewTextFile(fname: String);
  18. { fname - name of Text File to display }
  19.  
  20. Const
  21.   Bad   = #255;
  22.   Null  = #0;
  23.   ESC   = #27;
  24.   Home  = #71;
  25.   PgUp  = #73;
  26.   PgDn  = #81;
  27.   Done     : Boolean = False;
  28.   PageIndex: Word    = 1;         { index to our screen/page        }
  29.  
  30. Var
  31.   InFile : File;                  { unTyped File                    }
  32.   PFile  : Pointer;               { Pointer to our heap area        }
  33.   Size,                           { size of File                    }
  34.   Result,                         { return code For BlockRead       }
  35.   FileSeg,                        { Segment address of File in heap }
  36.   off: Word;                      { use as offset to our heap       }
  37.   Pages: Array[1..2000] of Word;  { define screen as Array of Words }
  38.   ch: Char;                       { For reading commands            }
  39.  
  40. begin
  41.   Assign(InFile, fname);
  42.   {$I-} Reset(InFile, 1); {$I+}
  43.   if IOResult <> 0 then
  44.     begin
  45.       Writeln('File not found: ',fname);
  46.       Halt(1)         { stop Program & return to Dos }
  47.     end;
  48.   Size := FileSize(InFile);        { get size of File               }
  49.   GetMem(PFile, Size);             { allocate space in heap         }
  50.   FileSeg := Seg(PFile^);          { get Segment address of File in heap }
  51.  
  52.   BlockRead(InFile, PFile^, Size, Result); { use BlockRead For fast File I/O }
  53.   FillChar(Pages, SizeOf(Pages), 0);       { fill page With zeroes--ie:blank }
  54.   Repeat
  55.     ClrScr;
  56.     off := Pages[PageIndex];
  57.     Repeat                                 { display screenfull at a time }
  58.       Write(Chr(Mem[FileSeg:off]));
  59.       inc(off);
  60.     Until (off = Size) or (WhereY = 25);
  61.     Repeat                                 { inner event loop }
  62.       ch := ReadKey;
  63.       if ch = ESC then
  64.         Done := True         { user escaped }
  65.       else
  66.         if ch = Null then
  67.           Case ReadKey of
  68.             Home:  PageIndex := 1;       { go to first page }
  69.             PgUp:  if PageIndex > 1 then
  70.                      Dec(PageIndex);
  71.             PgDn:  if off < Size then
  72.                      begin
  73.                        Inc(PageIndex);
  74.                        Pages[PageIndex] := off;
  75.                      end
  76.             else
  77.               ch := Bad
  78.           end;
  79.     Until (ch = Null) or Done;
  80.   Until Done;
  81.   Close(InFile)        { don't forget to close the File }
  82. end; { DisplayTextFile }
  83.  
  84.  
  85. begin
  86.   if ParamCount > 0 then
  87.     ViewTextFile(ParamStr(1))
  88.   else
  89.     Writeln('Error: Missing File parameter.')
  90. end. { program }
  91.  
  92.